package com.xiaobingby.admin.sys.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.xiaobingby.admin.sys.entity.Dict;
import com.xiaobingby.admin.sys.service.IDictService;
import com.xiaobingby.common.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Arrays;

/**
 * <p>
 * 字典管理
 * </p>
 *
 * @author XiaoBingBy
 * @since 2019-01-16
 */
@RestController
@RequestMapping("/sys/dict")
public class DictController extends BaseController<IDictService, Dict, Long> {

    @Autowired
    private IDictService iDictService;

    /**
     * 添加字典
     *
     * @param dict
     * @return
     */
    @ResponseBody
    @PostMapping
    public R addDict(@RequestBody Dict dict) {
        boolean save = iDictService.save(dict);
        return R.ok(save);
    }

    /**
     * 修改字典
     *
     * @param role
     * @return
     */
    @ResponseBody
    @PutMapping
    public R updateDict(@RequestBody Dict dict) {
        boolean result = iDictService.updateById(dict);
        return R.ok(result);
    }

    /**
     * 删除字典
     *
     * @param ids
     * @return
     */
    @ResponseBody
    @DeleteMapping("{ids}")
    public R delDict(@PathVariable Long[] ids) {
        boolean result = iDictService.removeByIds(Arrays.asList(ids));
        return R.ok(result);
    }

}
